home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2006 November
/
PCWorld_2006-11_cd.bin
/
domacnost a kancelar
/
findgraph
/
fgraph.exe
/
{app}
/
TestVB
/
Form1.frm
< prev
next >
Wrap
Text File
|
2005-10-13
|
11KB
|
386 lines
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
Caption = "FindGraph automation, sample 1"
ClientHeight = 4140
ClientLeft = 7365
ClientTop = 345
ClientWidth = 4980
LinkTopic = "Form1"
ScaleHeight = 4140
ScaleWidth = 4980
Begin VB.CommandButton Digitize
Caption = "Digitize"
Height = 516
Left = 3360
Picture = "Form1.frx":0000
Style = 1 'Graphical
TabIndex = 5
ToolTipText = "Add picture and digitize blue line"
Top = 3480
Width = 1452
End
Begin VB.CommandButton TestAddOne
Caption = "Add One"
Height = 516
Left = 3360
Picture = "Form1.frx":0312
Style = 1 'Graphical
TabIndex = 2
ToolTipText = "Add 20 points on one"
Top = 1318
Width = 1452
End
Begin MSComctlLib.ListView ListView1
Height = 3375
Left = 120
TabIndex = 6
Top = 600
Width = 3135
_ExtentX = 5530
_ExtentY = 5953
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin VB.CheckBox CheckVisible
Caption = "Visible FindGraph"
Height = 195
Left = 3360
TabIndex = 0
ToolTipText = "Show/Hide FindGraph"
Top = 240
Value = 1 'Checked
Width = 1572
End
Begin VB.CommandButton TestProp
Caption = "Properties"
Height = 516
Left = 3360
Picture = "Form1.frx":0624
Style = 1 'Graphical
TabIndex = 4
ToolTipText = "Change plot tile and scales"
Top = 2760
Width = 1452
End
Begin VB.CommandButton TestGet
Caption = "Get"
Height = 516
Left = 3360
Picture = "Form1.frx":0936
Style = 1 'Graphical
TabIndex = 3
ToolTipText = "Create new area and get all points selected"
Top = 2040
Width = 1452
End
Begin VB.CommandButton TestAddArray
Caption = "Add Array"
Height = 516
Left = 3360
Picture = "Form1.frx":0C48
Style = 1 'Graphical
TabIndex = 1
ToolTipText = "Add 500 points at once"
Top = 600
Width = 1452
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetModuleFileName Lib "kernel32" _
Alias "GetModuleFileNameA" _
(ByVal hModule As Long, _
ByVal lpFileName As String, _
ByVal nSize As Long) As Long
Dim FindGraph As Object
Sub LogError()
Print "error " & Err.Description
End Sub
Private Sub Form_Load()
On Error GoTo ErrHandler
' Create object FindGraph
Set FindGraph = CreateObject("FindGraph.Document")
' Run program FindGraph in new window
FindGraph.AppInit (1)
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error GoTo ErrHandler
' Close FindGraph application
FindGraph.AppQuit
ErrHandler:
Set FindGraph = Nothing
End Sub
' The example how to hide/show FindGraph main window
Private Sub CheckVisible_Click()
FindGraph.Visible = CheckVisible.Value 'True
End Sub
' The example how to add series of points
' Create new series named "VB_series"
' Add 500 points at once
Private Sub TestAddArray_Click()
On Error GoTo ErrHandler
Dim dwId, it, N As Long
Dim fX, fY, fZ As Double
N = 500
Dim va(1500) As Variant ' dimension N*3
' Create new series of points
dwId = FindGraph.DotsNew(2, 2, 20, 1, "VB_series")
' Set the identifier of a series
FindGraph.ArrayId = dwId
' Fill array with points
For i = 1 To N
fX = CDbl(8# / N * i)
fY = CDbl(5# / N * i)
fZ = CDbl(i)
it = (i - 1) * 3
va(it) = fX
va(it + 1) = fY
va(it + 2) = fZ
Next i
' Add all array at once
FindGraph.ArrayVar = va
' Repaint points
FindGraph.DotsUpdate dwId
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
' The example how to add one point to series
' Create new series named "VB_point"
' Add 20 points on one
Private Sub TestAddOne_Click()
On Error GoTo ErrHandler
Dim dwId, it, N As Long
Dim fX, fY, fZ As Double
N = 20
' Create new series of points
dwId = FindGraph.DotsNew(1, 1, 50, 1, "VB_point")
For i = 1 To N
fX = CDbl(0.3 * i)
fY = CDbl(0.4 * i)
' Add single point to series
FindGraph.DotsAddPoint dwId, fX, fY, 0
' Repaint points
FindGraph.DotsUpdate dwId
Next i
FindGraph.DotsUpdate dwId
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
' Create and select new area named "clip"
' Use nodes from VARIANT var array
Private Sub NewClip()
Dim dwId As Long
On Error GoTo ErrHandler
dwId = FindGraph.ClipNewEmptyRgn(1) ' BLUE
FindGraph.ArrayId = dwId
' Nodes (X,Y)
Dim va(12) As Variant ' dimension 4*3
va(0) = 1# '(1,5)
va(1) = 5#
va(2) = 0#
va(3) = 5# '(5,8)
va(4) = 8#
va(5) = 1#
va(6) = 7# '(7,5)
va(7) = 5#
va(8) = 2#
va(9) = 5# '(5,1)
va(10) = 1#
va(11) = 3#
' Create array of nodes
FindGraph.ArrayVar = va
' Select the area
FindGraph.ClipSelect dwId, 1
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
' The example how to create new area and get all points selected
Private Sub TestGet_Click()
On Error GoTo ErrHandler
Dim fX, fY, fZ As Double
ListInit
' Create new area and select it
NewClip
' GoTo ByOne
ByVar:
' The example how to get whole array of points immediately
' Points - three-tuples (X,Y,Z)
' Copy selected points, put it on the buffer.
' N number of points selected
N = FindGraph.SelectedGetStart(0)
Dim va As Variant
va = FindGraph.ArrayVar
NGet = (UBound(va) + 1) / 3
If N > NGet Then N = NGet
Print "ub"; UBound(va)
' Fill the grid with points (X, Y, Z)
For i = 1 To N
it = 3 * (i - 1)
fX = va(it)
fY = va(it + 1)
fZ = va(it + 2)
ListAdd fX, fY, fZ
Next i
' Free memory
FindGraph.SelectedGetStop (0)
Exit Sub
ByOne:
' The example how to get single point
' Points - three-tuples (X,Y,Z)
' Copy selected points, put it on the buffer.
' N number of points selected
N = FindGraph.SelectedGetStart(0)
Print "n"; N
' In cycle we choose points and add to grid
For i = 1 To N
fX = FindGraph.SelectedGetX(i - 1)
fY = FindGraph.SelectedGetY(i - 1)
fZ = FindGraph.SelectedGetZ(i - 1)
ListAdd fX, fY, fZ
Next i
' Free memory
FindGraph.SelectedGetStop (0)
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
' The example how to change plot properties
Private Sub TestProp_Click()
On Error GoTo ErrHandler
' Change the title
FindGraph.DocTitle = "From VB title"
' Change the scale of X axe
FindGraph.AxeXscale = 2
' Repaint
FindGraph.DocUpdate
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
' The example how to digitize the background picture
' Display the background picture
' Create rectangle area and select it
' Digitize blue line inside rectangle
' Create new series named "FromPict"
' Assign green color and radius of circle 1 mm to points of series
Private Sub Digitize_Click()
On Error GoTo ErrHandler
'Get file name from module path and exe name
Dim strFileName As String
Dim lngCount As Long
strFileName = String(512, 0)
lngCount = GetModuleFileName(App.hInstance, strFileName, 512)
strFileName = Left(strFileName, lngCount - 10) & "money.gif"
' Change the title
FindGraph.DocTitle = "Digitize Now"
' Set background picture file name
'FindGraph.DocPictFileName = "d:\vc\FindGraph\TestVB\money.gif"
FindGraph.DocPictFileName = strFileName
' Display background picture
FindGraph.DocPictIs = True
' rectangle in physical units from (1,4) to (10,8)
' Get axes scales
Dim fXStart, fXScale, fYStart, fYScale As Double
fXStart = FindGraph.AxeXstart
fXScale = FindGraph.AxeXscale
fYStart = FindGraph.AxeYstart
fYScale = FindGraph.AxeYscale
' Calculate rectangle
Dim fLeft, fTop, fRight, fBottom As Double
fLeft = fXStart + fXScale * 1#
fTop = fYStart + fYScale * 4#
fRight = fXStart + fXScale * 10#
fBottom = fYStart + fYScale * 8#
' Create rectangle area with color number = 2 (GREEN)
Dim dwIdArea As Long
dwIdArea = FindGraph.ClipNewRect(2, fLeft, fTop, fRight, fBottom)
' Select area
FindGraph.ClipSelect dwIdArea, 1
' Digitize points inside rectangle
' Color number = 1 (BLUE)
' Radius of digitizing = 20 (2.0 mm)
Dim dwIdDots As Long
dwIdDots = FindGraph.DotsFromPict(1, 20, "FromPict")
' Assign green color, color number = 2 (GREEN)
FindGraph.DotsColorNumSet dwIdDots, 2
' Assign radius of new points = 10 (1.0 mm)
FindGraph.DotsWidthSet dwIdDots, 10
' Repaint
FindGraph.DocUpdate
Exit Sub
ErrHandler:
LogError
Exit Sub
End Sub
Private Sub ListInit()
ListView1.ListItems.Clear
Dim Col As ColumnHeader ' Declare variable
Set Col = ListView1.ColumnHeaders.Add(, , "X", ListView1.Width / 3)
Set Col = ListView1.ColumnHeaders.Add(, , "Y", ListView1.Width / 3)
Set Col = ListView1.ColumnHeaders.Add(, , "Z", ListView1.Width / 3)
End Sub
Private Sub ListAdd(X, Y, Z)
Dim Insert As ListItem
Set Insert = ListView1.ListItems.Add(, , CStr(X))
Insert.SubItems(1) = CStr(Y)
Insert.SubItems(2) = CStr(Z)
End Sub